/*
 * =====================================================================================
 *
 *       Filename:  InetAddr.h
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  07/11/2012 09:29:53 PM
 *       Revision:  none
 *       Compiler:  gcc/g++
 *
 *         Author:  wangtengchao , wangtengchao AT gmail.com
 *   Organization:  
 *
 * =====================================================================================
 */
#ifndef INETADDR_H
#define INETADDR_H

#include"netinet/in.h"//for sockaddr_in  htons() htonl
namespace inm
{
	namespace net
	{
		//for IPV4 .wrap sockaddr_in and operations
    /*
        struct sockaddr_in
        {
            uint8_t sin_len;
            sa_family_t sin_family;
            in_port_t sin_port;
            struct in_addr sin_addr;   struct addr{ in_addr_t s_addr }
        }
        */
		class IpString;	
		class InetAddr
        {//set to net bytes
			public:
				//addr_ is not initialized by 0 because it will be initialized by parameter addr.
				//I think it will run correctly. It will be verified!
                InetAddr(const sockaddr_in& addr):addr_(addr){};
                //ip is INADDR_ANY  this should be default
				InetAddr(const uint16_t& port);
				//should be called like InetAddr("127.0.0.1",80)
                InetAddr(const IpString& ip,const uint16_t& port);
                const struct sockaddr_in& getSockAddr() const;//return sock_addr_in
                const struct in_addr& getInAddr() const;//return in_addr type---sin_addr
                in_addr_t getInAddrT() const;
                uint16_t getPort() const;
                void setSockAddr(const struct sockaddr_in& sockAddr);
				//string getHostName 

			private:
				//just for internal call
                void _setSockAddrIn(const uint32_t& ip,const uint16_t& port);
				struct sockaddr_in addr_;

		};

	};

};
#endif
